package org.dromara.system.api.services;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.AssertUtils;
import org.dromara.system.api.domain.bo.RemoteSocialBo;
import org.dromara.system.api.domain.vo.RemoteSocialVo;
import org.dromara.system.api.feign.SystemSocialClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/10/6 12:37
 * @version: v1
 */
@Slf4j
@Service("sysSocialApiService")
@RequiredArgsConstructor
public class SysSocialApiService {

    private final SystemSocialClient systemSocialClient;

    /**
     * 根据 authId 查询用户授权信息
     *
     * @param authId 认证id
     * @return 授权信息
     */
    public List<RemoteSocialVo> selectByAuthId(String authId) {
        R<List<RemoteSocialVo>> socialListByAuthIdResult = systemSocialClient.selectByAuthId(authId);
        AssertUtils.assertTrue(R.isSuccess(socialListByAuthIdResult), "根据authId查询用户授权信息失败");
        return socialListByAuthIdResult.getData();
    }

    /**
     * 查询列表
     *
     * @param remoteSocialBo 社会化关系业务对象
     */
    public List<RemoteSocialVo> querySocialList(RemoteSocialBo remoteSocialBo) {
        R<List<RemoteSocialVo>> socialListResult = systemSocialClient.querySocialList(remoteSocialBo);
        AssertUtils.assertTrue(R.isSuccess(socialListResult), "查询用户授权信息失败");
        return socialListResult.getData();
    }

    /**
     * 保存社会化关系
     *
     * @param remoteSocialBo 社会化关系业务对象
     */
    public void saveSocial(RemoteSocialBo remoteSocialBo) {
        systemSocialClient.saveSocial(remoteSocialBo);
    }

    /**
     * 更新社会化关系
     *
     * @param remoteSocialBo 社会化关系业务对象
     */
    public void updateSocial(RemoteSocialBo remoteSocialBo) {
        systemSocialClient.updateSocial(remoteSocialBo);
    }

    /**
     * 删除社会化关系
     *
     * @param socialId 社会化关系ID
     * @return 结果
     */
    public boolean delSocialById(Long socialId) {
        R<Boolean> delSocialResult = systemSocialClient.delSocialById(socialId);
        AssertUtils.assertTrue(R.isSuccess(delSocialResult), "取消授权失败");
        return delSocialResult.getData();
    }

}
